package com.jiuyun.auth.servlet;

import com.jiuyun.auth.dao.RoleDao;
import com.jiuyun.auth.dao.impl.RoleDaoImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.SQLException;
import java.util.Arrays;
import java.util.List;

@WebServlet("/role/*")
public class RoleServlet extends BaseServlet {

    RoleDao roleDao = new RoleDaoImpl();

    protected void page(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //显示角色授权页
        try {
            List list = roleDao.getList(); //所有角色
            request.setAttribute("roles",list);
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }

        request.getRequestDispatcher("/role.jsp").forward(request,response);
    }

    //给用户增加角色
    protected void add(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
       String roles[]= request.getParameterValues("myrole");
        System.out.println(Arrays.toString(roles));
    }
}
